package com.example.contadorcomida;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;

public class ConfiguracionActivity extends Activity{
	private OnClickListener listenerCheck = new OnClickListener() {
		@Override
		public void onClick(View v) {
			CheckBox check = (CheckBox) findViewById(R.id.checkActivar);
			guardarPreferences(check.isChecked()); 
		}
	};
	
	protected void guardarPreferences (boolean value){
		super.onStop(); 
		SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); 
		
		SharedPreferences.Editor editor = preferences.edit(); 
		
		editor.putBoolean("valor", value) ; 
		editor.commit(); 
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.configuration_main); 
		
		findViewById(R.id.checkActivar).setOnClickListener(this.listenerCheck); 
		
		boolean estaActivada = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("valor", false);
		
		CheckBox check = (CheckBox) findViewById(R.id.checkActivar);
		check.setChecked(estaActivada);
		}
}
